/**
 * 非商机拜访记录
 * Created by wenchuan.li on 2019/3/25 10:40.
 */
define(function () {

    var self,
        app = win.app,
        searchData = {
            keyword: ''
        }
    ;

    app.newModule({

        init: function () {
            self = this;
            self._super({
                _refreshAutoInit: true
            }, win);
        },
        _initRefresh: function () { // 实例化刷新组件
            if (self._refreshIds.length == 0) {
                self._refreshIds = ['scroll1'];
            }
            this._super(win);
        },
        _refreshCb: function (obj) {// 刷新组件回调函授
            var _super = this._super;
            app.ajax({
                xurl: "api/wx/bfjltb1/getBfjltb1List",
                xdata: {
                    page:obj.page+1,
                    limit: obj.limit,
                    keyword: searchData.keyword
                },
                cb: function (result) {
                    if (result.ok) {
                        var data = result.data;
                        _super({
                            obj: obj,
                            data: data.data,
                            nodata: '无拜访记录信息...'
                        });
                    }
                }
            });
        },
        _ready: function () { // dom载入完成后执行

            Vue.component('bfjltb1item', {
                template: app.getByid(doc, 'bfjltb1item-template'),
                props: {
                    model: Array
                },
                methods: {
                    open: function (item) {
                        app.openPage({
                            src: 'hn-bfjltb1/bfjltb-edit.html',
                            args: {
                                item: app.cloneJSON(item),
                                cb: function () {
                                    self._refresh();
                                }
                            }
                        });
                    },
                    deleteItem: function (item, _node) {
                        if (item.GWBNACTI == 'Y') {
                            app.alert({msg: '已审核无法删除！'});
                            return;
                        }
                        if (item.GWBNACTI == 'S') {
                            app.alert({msg: '已结案无法删除！'});
                            return;
                        }
                        app.ajax({
                            xurl: "api/wx/bfjltb1/delBfjl",
                            loading: true,
                            xdata: {
                                GWBNID: item.GWBNID,
                                GWBNSEQ: item.GWBNSEQ
                            },
                            confirm: {
                                msg: '是否删除拜访记录？'
                            },
                            cb: function (result) {
                                if (result.ok) {
                                    app.alert({
                                        msg: '拜访记录删除成功'
                                    });
                                    self._getRefreshObj().data.remove(item);
                                    mui.swipeoutClose($(_node.target).parents("li").get(0));
                                }
                            }
                        });
                    }
                }
            });
        },
        _search: function (data) {
            searchData.keyword = data.keyword.trim();
            self._refresh();
        },
        _lazy: function () { // 延迟300ms加载
            this._super();
            app.taps.call(win, [
                {
                    o: 'addBtn',
                    cb: function () {
                        app.openPage({
                            src: 'hn-bfjltb1/bfjltb-add.html',
                            args: {
                                cb: function () {
                                    self._refresh();
                                }
                            }
                        });
                    }
                }
            ]);
        }
    });

});